package com.xhs.config;

import com.mybatisflex.core.FlexGlobalConfig;
import com.mybatisflex.core.audit.AuditManager;
import com.mybatisflex.spring.boot.MyBatisFlexCustomizer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @desc: mybatis-Flex全局配置
 * @projectName: mybatis-flex-demo
 * @author: xhs
 * @date: 2023-09-13 17:56
 * @version: JDK 1.8
 */
@Slf4j
@Configuration
public class MyBatisFlexConfig implements MyBatisFlexCustomizer {

    @Resource
    private ConsoleMessageCollector consoleMessageCollector;
    @Resource
    private ConsoleMessageReporter consoleMessageReporter;

    @Override
    public void customize(FlexGlobalConfig flexGlobalConfig) {

//        // 注册全局数据填充监听器
//        flexGlobalConfig.registerInsertListener(new EntityListener(), BaseEntity.class);
//        flexGlobalConfig.registerUpdateListener(new EntityListener(), BaseEntity.class);

//        // 全局配置逻辑删除字段
//        flexGlobalConfig.setLogicDeleteColumn("is_deleted");

        // 开启审计功能
        AuditManager.setAuditEnable(true);

        // 设置SQL审计收集器
        AuditManager.setMessageReporter(consoleMessageReporter);

        // 设置SQL输出到控制台
        AuditManager.setMessageCollector(consoleMessageCollector);
    }

//    /**
//     * 自定义逻辑删除处理功能
//     *
//     * @return LogicDeleteProcessor
//     */
//    @Bean
//    public LogicDeleteProcessor logicDeleteProcessor() {
//        log.info("-----------------自定义逻辑删除处理功能-----------------");
//        return new MyBatisFlexLogicDelete();
//    }
}
